<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-basic__house}">
      <search-bar ref="SearchBar" model="birth" :fields="searchFields" @add="addOrUpdateHandle" @search="search"></search-bar>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column v-for="field in m_ltFields" :key="field.prop" :prop="field.prop" :fixed="field.fixed" :label="field.label" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('stock:birth:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('stock:birth:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataListEx"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './house-add-or-update'
import SearchBar from '../components/search-bar'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/basic/house/page',
        getDataListIsPage: true,
        exportURL: '/basic/house/export',
        deleteURL: '/basic/house',
        deleteIsBatch: true
      },
      m_ltFields: [ { prop: 'name', label: '名称', fixed: 'left', required: true, search: true }, { prop: 'stage', label: '阶段', required: true, search: true }, { prop: 'max', label: '最大存栏' }, { prop: 'grid', label: '栏位类型', type: 'number' }, { prop: 'rows', label: '行数', type: 'number', required: true, search: true }, { prop: 'columns', label: '列数', type: 'number' }, { prop: 'remark', label: '备注' }, { prop: 'creator', label: '创建者', readonly: true }, { prop: 'createDate', label: '创建时间', readonly: true } ],
      searchFields: [ { prop: 'name', placeholder: '猪舍名称', fixed: 'left', readonly: true, search: true } ]
    }
  },
  components: {
    AddOrUpdate,
    SearchBar
  }
}
</script>
